#include "../common.h"

class Solution
{
public:
    int reverse(int x)
    {
        long n = x;
        long i = 1;

        while (n != 0)
        {
            n /= 10;
            i *= 10;
        }

        i /= 10;
        n = 0;

        while (x != 0)
        {
            n += (x % 10) * i;
            i /= 10;
            x /= 10;
        }

        return INT_MAX < n || INT_MIN > n ? 0 : n;
    }
};